package com.njupt.swg.threadstudyjimin.item06.immutable;

import com.google.common.collect.Maps;
import com.njupt.swg.threadstudyjimin.annotation.NotThreadSafe;
import java.util.Map;

@NotThreadSafe
public class ImmutableExample1 {
    private final static Integer a = 1;
    private final static String b = "sss";
    private final static Map<Integer,Integer> map = Maps.newHashMap();

    static {
        map.put(1,2);
        map.put(3,4);
        map.put(5,6);
    }

    public static void main(String[] args) {
        //a = 1;     //编译出错
        //a = 2;     //编译出错
        //b = "sss";  //编译出错
        //b = "ttt";  //编译出错
        //map = Maps.newHashMap();     //编译出错
        System.out.println(map.get(1));  //2
        map.put(1,3);   //值可以修改，所以会引发线程安全问题
        System.out.println(map.get(1));  //3
    }
}
